package com.twu.biblioteca.view.consoleUI.viewActions;

import com.twu.biblioteca.model.LibraryItem;
import com.twu.biblioteca.model.menu.Menu;
import com.twu.biblioteca.view.ViewAction;

import java.io.PrintStream;

public class ListViewAction implements ViewAction {

    private final PrintStream output;
    private final Menu menu;
    private final Class itemClass;

    public ListViewAction(PrintStream output, Menu menu, Class itemClass) {
        this.output = output;
        this.menu = menu;
        this.itemClass = itemClass;
    }

    @Override
    public void update(boolean success) {
        if (success) {
            output.println("Available: ");
            for (LibraryItem item : menu.getLibrary().getInventory())
                if (item.getClass() == itemClass && !item.isCheckedOut()) {
                    output.println(item.toString());
                }
        }
    }
}
